home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / s342q07.lha / bio.c < prev    next >
C/C++ Source or Header  |  1995-08-08  |  5KB  |  209 lines

  1. /*
  2. *       bio.c
  3. *
  4. * User Biography Functions.
  5. */
  6. /*
  7. *       history
  8. *
  9. * 91Jun14 HAW  Created.
  10. */
  11. #include "ctdl.h"
  12. /*
  13. *       contents
  14. *
  15. * BioDirectory()    Gets a list of user biographies.
  16. * ClearBio()    This clears a bio from disk.
  17. * EditBio()   Edits a biography by a user.
  18. * GetBioInfo()    Gets a bio from disk.
  19. * SaveBioInfo()   Save a bio to disk.
  20. */
  21. extern CONFIG      cfg;   /* Lots an lots of variables    */
  22. extern logBuffer   logBuf;    /* Person buffer    */
  23. extern logBuffer   logTmp;    /* Person buffer    */
  24. extern MessageBuffer     msgBuf;
  25. extern char    haveCarrier;    /* Do we still got carrier?     */
  26. extern int     thisLog;
  27. extern char    *LCHeld, *WRITE_ANY, *READ_ANY;
  28. extern char    outFlag;    /* Output flag     */
  29. extern char    onConsole;
  30. extern char    MsgEntryType;
  31. /**
  32.   InitBio()
  33.   This function will check to see if the bioArea exists and
  34.   will create it if it does not.
  35. **/
  36. void InitBio()
  37.   {
  38.   if( access(cfg.bioArea.saDirname, F_OK)) return;
  39.   mkdir((char *)&cfg.bioArea.saDirname);
  40.   }
  41. /*
  42. * EditBio()
  43. *
  44. * This function allows the editing of a biography.  If a biography already
  45. * exists then an option is offered to edit that rather than create a new
  46. * biography.  NB: "null" biographies are not saved but are rather completely
  47. * deleted so they don't show up on .M?
  48. */
  49. void EditBio()
  50.   {
  51.   char name[15];
  52.   SYS_FILE bio;
  53.   doCR();
  54.   sPrintf(name, "%d.bio", thisLog);
  55.   MakeBioName(bio, name);
  56.   if (cfg.BoolFlags.debug)
  57.     {
  58.     splitF(NULL,"EditBio:%s\n",bio);
  59.     };
  60.   if (access(bio, 0) == 0)
  61.     {
  62.     if (getYesNo("EDBIOS"))
  63.       {
  64.       GetBioInfo(thisLog);
  65.  
  66.       }
  67.     else msgBuf.mbtext[0] = 0;
  68.  
  69.     }
  70.   else msgBuf.mbtext[0] = 0;
  71.  
  72.   Output_Citadel_Message("BIONOV",NULL,NULL,NULL);
  73.   HelpIfPresent("biosys.blb");
  74.   MsgEntryType = BIO_ENTRY;
  75.   Output_Citadel_Message("MYBIOS",NULL,NULL,NULL);
  76.   doCR();
  77.   CleanEnd(msgBuf.mbtext);
  78.   mPrintf("%s", msgBuf.mbtext);
  79.   outFlag = OUTOK;
  80.   if (GetBalance(ASCII, msgBuf.mbtext, MAXTEXT-50) && onLine())
  81.     {
  82.     CleanEnd(msgBuf.mbtext);
  83.     if (strLen(msgBuf.mbtext) < 3)
  84.     ClearBio(thisLog);
  85.     else SaveBioInfo(thisLog);
  86.  
  87.     }
  88.  
  89.   }
  90. /*
  91. * GetBioInfo()
  92. *
  93. * This function handles the mechanics of getting biographical info.  It
  94. * handles the encryption.
  95. */
  96. char GetBioInfo(int which)
  97.   {
  98.   char name[15];
  99.   SYS_FILE bio;
  100.   FILE *fd;
  101.   long size;
  102.   sPrintf(name, "%d.bio", which);
  103.   MakeBioName(bio, name);
  104.   if (cfg.BoolFlags.debug)
  105.     {
  106.     splitF(NULL,"GetBio:%s\n",bio);
  107.     };
  108.   if ((fd = fopen(bio, READ_ANY)) != NULL)
  109.     {
  110.     totalBytes(&size, fd);
  111.     size++;       /* include NULL byte */
  112.     fread(msgBuf.mbtext, (int) size, 1, fd);
  113.     crypte(msgBuf.mbtext, (int) size, which);
  114.     fclose(fd);
  115.     return TRUE;
  116.  
  117.     }
  118.   msgBuf.mbtext[0] = 0;
  119.   return FALSE;
  120.  
  121.   }
  122. /*
  123. * SaveBioInfo()
  124. *
  125. * This function handles the mechanics of saving biographical info.  This
  126. * includes encrypting the bio before saving it.
  127. */
  128. void SaveBioInfo(int which)
  129.   {
  130.   char name[15];
  131.   SYS_FILE bio;
  132.   FILE *fd;
  133.   int size;
  134.   sPrintf(name, "%d.bio", which);
  135.   MakeBioName(bio, name);
  136.   if (cfg.BoolFlags.debug)
  137.     {
  138.     splitF(NULL,"SaveBio:%s\n",bio);
  139.     };
  140.   if ((fd = fopen(bio, WRITE_ANY)) != NULL)
  141.     {
  142.     size = strLen(msgBuf.mbtext) + 1; /* include NULL byte */
  143.     crypte(msgBuf.mbtext, (int) size, which);
  144.     fwrite(msgBuf.mbtext, (int) size, 1, fd);
  145.     crypte(msgBuf.mbtext, (int) size, which);
  146.     fclose(fd);
  147.  
  148.     }
  149.   else msgBuf.mbtext[0] = 0;
  150.  
  151.   }
  152. /*
  153. * ClearBio()
  154. *
  155. * This clears out a biography.
  156. */
  157. void ClearBio(int which)
  158.   {
  159.   char name[15];
  160.   SYS_FILE bio;
  161.   sPrintf(name, "%d.bio", which);
  162.   MakeBioName(bio, name);
  163.   if (cfg.BoolFlags.debug)
  164.     {
  165.     splitF(NULL,"ClearBio:%s\n",bio);
  166.     };
  167.   unlink(bio);
  168.  
  169.   }
  170. static  void ShowBioName(DirEntry *);
  171. /*
  172. * BioDirectory()
  173. *
  174. * This shows who's written biographies.  Rather ugly since we're between
  175. * major releases.  If we do another major release we should clean out
  176. * that call to MoveToBioDirectory().
  177. */
  178. void BioDirectory()
  179.   {
  180.   if (cfg.BoolFlags.debug)
  181.     {
  182.     splitF(NULL,"BioArea:%s\n",cfg.bioArea.saDirname);
  183.     };
  184.   MoveToBioDirectory();
  185.   if (wildCard(ShowBioName, "*.bio", FALSE, "", FALSE) == 0)
  186.     {
  187.     Output_Citadel_Message("NOBIOS",NULL,NULL,NULL);
  188.     }
  189.   else mPrintf("\b\b. \n ");
  190.   homeSpace();
  191.  
  192.   }
  193. /*
  194. * ShowBioName()
  195. *
  196. * This internal function shows the name of a person with a bio.  It is called
  197. * in connection with RunList() (see above).
  198. */
  199. static void ShowBioName(DirEntry *entry)
  200.   {
  201.   char *dot;
  202.   if ((dot = strchr(entry->unambig, '.')) == NULL) return;
  203.   *dot = 0;
  204.   getLog(&logTmp, atoi(entry->unambig));
  205.   if (logTmp.lbflags.L_INUSE)
  206.   mPrintf("%s, ", logTmp.lbname);
  207.  
  208.   }
  209.